
//<!--begin
/*
 * Copyright (C) 2000-2007 Wang Pengcheng <wpc0000@163.com>
 * Licensed to the Wang Pengcheng under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The LGPL licenses this file to You under the GNU Lesser General Public
 * Licence, Version 2.0  (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * 28 Aug 2007
 */
package com.hello.base.databaseAction;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;

import java.io.Reader;
import java.io.IOException;
import java.util.*;
import java.sql.SQLException;

import com.hello.base.database.ItemBean;

public class ItemAction {

	/**
	 * SqlMapClient instances are thread safe, so you only need one. In this
	 * case, we'll use a static singleton. So sue me. ;-)
	 */
	private static SqlMapClient sqlMapper;

	/**
	 * It's not a good idea to put code that can fail in a class initializer,
	 * but for sake of argument, here's how you configure an SQL Map.
	 */
	static {
		try {
			Reader reader = Resources
					.getResourceAsReader("com/hello/base/databaseAction/SQLMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(
					"Something bad happened while building the SqlMapClient instance."
							+ e, e);
		}
	}

	//<!--select all
	public static List<ItemBean> selectAllItemBeans() throws SQLException {
		return sqlMapper.queryForList("selectAllItemBeans");
	}

	//<!--select one list
	//<!--select one object
	public static ItemBean selectItemBeanById(int id) throws SQLException {
		return (ItemBean) sqlMapper.queryForObject("selectItemBeanById", id);
	}

	//<!--insert
	public static void insertItemBean(ItemBean ItemBean) throws SQLException {
		sqlMapper.insert("insertItemBean", ItemBean);
	}

	//<!--update
	public static void updateItemBean(ItemBean ItemBean) throws SQLException {
		sqlMapper.update("updateItemBean", ItemBean);
	}

	//<!--delete one
	public static void deleteItemBeanById(int id) throws SQLException {
		sqlMapper.delete("deleteItemBeanById", id);
	}

	//<!--delete all
	public static void deleteAllItemBeans() throws SQLException {
		sqlMapper.delete("deleteAllItemBeans");
	}
	
	//<!--end
}
